<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<%@ page import="java.text.DateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Random" %>
<% 
if(request.getParameter("type") != null) {
	String type = request.getParameter("type");
	out.println("<root>");
	if(type.equalsIgnoreCase("DataItems")) {
		out.println("<dataitem>");
		out.println("<name>roomtemp_101</name>");
		out.println("<category>Science Center</category>");
		out.println("<units>degrees farenheit</units>");
		out.println("</dataitem>");	
		out.println("<dataitem>");
		out.println("<name>roomtemp_102</name>");
		out.println("<category>Science Center</category>");
		out.println("<units>degrees farenheit</units>");
		out.println("</dataitem>");	
		out.println("<dataitem>");
		out.println("<name>roomtemp_M120</name>");
		out.println("<category>Murdock</category>");
		out.println("<units>degrees farenheit</units>");
		out.println("</dataitem>");	
		out.println("<dataitem>");
		out.println("<name>roomtemp_M108</name>");
		out.println("<category>Murdock</category>");
		out.println("<units>degrees farenheit</units>");
		out.println("</dataitem>");	
		out.println("<dataitem>");
		out.println("<name>roomtemp_M218</name>");
		out.println("<category>Murdock</category>");
		out.println("<units>degrees farenheit</units>");
		out.println("</dataitem>");	
		out.println("<dataitem>");
		out.println("<name>roomtemp_B102</name>");
		out.println("<category>Bowman</category>");
		out.println("<units>degrees farenheit</units>");
		out.println("</dataitem>");	
		out.println("<dataitem>");
		out.println("<name>roomtemp_B118</name>");
		out.println("<category>Bowman</category>");
		out.println("<units>degrees farenheit</units>");
		out.println("</dataitem>");	
	}
	else if(type.equalsIgnoreCase("Categories")) {
		out.println("<category>");
		out.println("<name>Science Center</name>");
		out.println("</category>");	
		out.println("<category>");
		out.println("<name>Murdock</name>");
		out.println("</category>");	
		out.println("<category>");
		out.println("<name>Bowman</name>");
		out.println("</category>");	
	}
	else if(type.equals("Data")) {
		Random random = new Random();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
		Date startDate = df.parse(request.getParameter("startTime"));
		Calendar start = Calendar.getInstance();
		Date endDate = df.parse(request.getParameter("endTime"));
		Calendar end = Calendar.getInstance();
		out.println("<timescale>Time (5 minute intervals)</timescale>");
		int numPoints = Integer.parseInt(request.getParameter("numPoints"));
		int dataItemIndex = 0;
		while(request.getParameter("dataItem" + dataItemIndex) != null) {
			start.setTime(startDate);
			end.setTime(endDate);
			String dataItem = request.getParameter("dataItem" + dataItemIndex);
			out.println("<dataitem>");
			out.println("<name>" + dataItem + "</name>");
			out.println("<datalist>");
			for(int i = 0; i < numPoints; i++) {
				start.add(Calendar.MINUTE, 5);
				out.println("<data>");
				out.println("<time>"+df.format(start.getTime())+"</time>");
				out.println("<value>"+(random.nextDouble()*100)+"</value>");
				out.println("</data>");
			}
			out.println("</datalist>");
			out.println("</dataitem>");
			dataItemIndex++;
		}
	}
	out.println("</root>");
}
%>
